home *** CD-ROM | disk | FTP | other *** search
/ Czech Logic, Card & Gambling Games / Logické hry.iso / hry / Fish Fillets / script / share / blackjokes.lua < prev    next >
Encoding:
Text File  |  2005-07-16  |  8.4 KB  |  238 lines

  1.  
  2. function stdBlackJokeLoad()
  3.     dialogLoad("script/share/black_", "sound/share/blackjokes/")
  4. end
  5.  
  6. -- -----------------------------------------------------------------
  7. local autoRestart = false
  8. local restartCountDown = 0
  9. local function initAutoRestart()
  10.     autoRestart = true
  11.     restartCountDown = 80
  12. end
  13. local function autoRestartTick()
  14.     if autoRestart then
  15.         restartCountDown = restartCountDown - 1
  16.         if restartCountDown == 0 then
  17.             autoRestart = false
  18.             level_action_restart()
  19.         end
  20.     end
  21. end
  22.  
  23. -- -----------------------------------------------------------------
  24. local alive_time = 0
  25. --TODO: remember values to the next restart
  26. local PoslSmrtMale = -1
  27. local PoslSmrtVelke = -1
  28. local PoslSmrtObou = 0
  29.  
  30. -- NOTE: uses 'small' and 'big' names for fishes
  31. function stdBlackJoke()
  32.     local hzadna,hbezna,hzertik,hmiluji,hzahrobni,hobe,hauto
  33.         = 1, 2, 3, 4, 5, 6, 7
  34.     local hlaska
  35.     local hlrestart
  36.     local h
  37.  
  38.     if level_getDepth() == 2 then
  39.         return
  40.     end
  41.     if small:isAlive() and big:isAlive() then
  42.         alive_time = game_getCycles()
  43.     else
  44.         hlaska = hzadna
  45.         hlrestart = false
  46.         if (not small:isAlive() or not big:isAlive()) and alive_time + 8 == game_getCycles() then
  47.             if isReady(big) or isReady(small) then
  48.                 local joke_table = {
  49.                     [1] = function()
  50.                         hlaska = hbezna
  51.                         hlrestart = true
  52.                     end,
  53.                     [3] = function()
  54.                         if random(100) < 70 then
  55.                             hlaska = hbezna
  56.                         end
  57.                         if random(100) < 50 or PoslSmrtMale == -1 and PoslSmrtVelke == -1 then
  58.                             hlrestart = true
  59.                         end
  60.                     end,
  61.                     [4] = function()
  62.                         if random(100) < 80 - 5 * level_getDepth() then
  63.                             if small:isAlive() then
  64.                                 if random(100) < 5 then
  65.                                     hlaska = hzertik
  66.                                 else
  67.                                     hlaska = hbezna
  68.                                 end
  69.                             elseif random(100) < 10 then
  70.                                 hlaska = hzertik
  71.                             else
  72.                                 hlaska = hbezna
  73.                             end
  74.                         else
  75.                             hlaska = hzadna
  76.                         end
  77.                         hlrestart = random(100) < 90 - 10 * level_getDepth()
  78.                         if hlaska ~= hzadna then
  79.                             if small:isAlive() and random(100) < 6 or big:isAlive() and random(100) < 10 then
  80.                                 hlaska = hzahrobni
  81.                                 hlrestart = false
  82.                             end
  83.                         end
  84.                     end,
  85.                     [9] = function()
  86.                         if random(100) < 30 then
  87.                             if small:isAlive() then
  88.                                 if random(100) < 8 then
  89.                                     if random(8) < 5 then
  90.                                         hlaska = hzertik
  91.                                     else
  92.                                         hlaska = hmiluji
  93.                                     end
  94.                                 else
  95.                                     hlaska = hbezna
  96.                                 end
  97.                             elseif random(100) < 10 then
  98.                                 hlaska = hzertik
  99.                             else
  100.                                 hlaska = hbezna
  101.                             end
  102.                         else
  103.                             hlaska = hzadna
  104.                         end
  105.                         hlrestart = random(100) < 5
  106.                         if hlaska ~= hzadna then
  107.                             if small:isAlive() and random(100) < 10 or big:isAlive() and random(100) < 18 then
  108.                                 hlaska = hzahrobni
  109.                                 hlrestart = false
  110.                             end
  111.                         end
  112.                     end,
  113.                     [15] = function()
  114.                         hlaska = hauto
  115.                         hlrestart = false
  116.                         initAutoRestart()
  117.                     end,
  118.                 }
  119.  
  120.                 joke_table[2] = joke_table[1]
  121.  
  122.                 joke_table[5] = joke_table[4]
  123.                 joke_table[6] = joke_table[4]
  124.                 joke_table[7] = joke_table[4]
  125.                 joke_table[8] = joke_table[4]
  126.  
  127.                 joke_table[10] = joke_table[9]
  128.                 joke_table[11] = joke_table[9]
  129.                 joke_table[12] = joke_table[9]
  130.                 joke_table[13] = joke_table[9]
  131.                 joke_table[14] = joke_table[9]
  132.  
  133.                 switch(level_getDepth())(joke_table)
  134.             elseif not small:isOut() and not big:isOut() then
  135.                 if level_getDepth() >= 9 and random(100) < 25 then
  136.                     hlaska = hobe
  137.                 else
  138.                     hlaska = hzadna
  139.                 end
  140.                 hlrestart = false
  141.             end
  142.         end
  143.         if isReady(small) then
  144.             switch(hlaska){
  145.                 [hzadna] = function()
  146.                 end,
  147.                 [hbezna] = function()
  148.                     repeat
  149.                         h = random(5) + 1
  150.                     until h ~= PoslSmrtVelke
  151.                     PoslSmrtVelke = h
  152.                     addm(random(5), "smrt-m-"..h)
  153.                 end,
  154.                 [hzertik] = function()
  155.                     PoslSmrtVelke = 0
  156.                     addm(random(5), "smrt-m-0")
  157.                 end,
  158.                 [hmiluji] = function()
  159.                     if PoslSmrtVelke == 6 then
  160.                         h = 0
  161.                     else
  162.                         h = 6
  163.                     end
  164.                     PoslSmrtVelke = h
  165.                     addm(random(5), "smrt-m-"..h)
  166.                 end,
  167.                 [hzahrobni] = function()
  168.                     if PoslSmrtVelke ~= 10 then
  169.                         PoslSmrtVelke = 10
  170.                         addv(random(30) + 20, "smrt-v-zahrobi")
  171.                     end
  172.                 end,
  173.                 [hauto] = function()
  174.                     if PoslSmrtVelke ~= 20 or random(50) < 100 then
  175.                         PoslSmrtVelke = 20
  176.                         addm(0, "smrt-m-autorest")
  177.                     end
  178.                 end,
  179.             }
  180.         elseif isReady(big) then
  181.             switch(hlaska){
  182.                 [hzadna] = function()
  183.                 end,
  184.                 [hbezna] = function()
  185.                     repeat
  186.                         h = random(4) + 1
  187.                     until h ~= PoslSmrtMale
  188.                     PoslSmrtMale = h
  189.                     addv(random(5), "smrt-v-"..h)
  190.                 end,
  191.                 [hzertik] = function()
  192.                     repeat
  193.                         h = random(4)
  194.                         if h > 0 then
  195.                             h = h + 4
  196.                         end
  197.                     until h ~= PoslSmrtMale
  198.                     PoslSmrtMale = h
  199.                     addv(random(5), "smrt-v-"..h)
  200.                 end,
  201.                 [hzahrobni] = function()
  202.                     if PoslSmrtMale ~= 10 and (PoslSmrtMale == 11 or random(100) < 50) then
  203.                         PoslSmrtMale = 10
  204.                         addm(random(30) + 20, "smrt-m-zahrobi")
  205.                     else
  206.                         PoslSmrtMale = 11
  207.                         addv(random(30) + 20, "smrt-v-posmrtny")
  208.                         addm(random(30) + 20, "smrt-m-posmrtny")
  209.                     end
  210.                 end,
  211.                 [hauto] = function()
  212.                     if PoslSmrtMale ~= 20 or random(50) < 100 then
  213.                         PoslSmrtMale = 20
  214.                         addv(0, "smrt-v-autorest")
  215.                     end
  216.                 end,
  217.             }
  218.         elseif hlaska == hobe and PoslSmrtObou ~= 1 then
  219.             PoslSmrtObou = 1
  220.             room:planDialog(0, "smrt-x-obe")
  221.             addv(2, "smrt-v-obe")
  222.             addm(0, "smrt-m-obe")
  223.         end
  224.         if hlrestart then
  225.             if isReady(big) then
  226.                 addv(random(20) + 10, "smrt-v-restart")
  227.             elseif isReady(small) then
  228.                 addm(random(20) + 10, "smrt-m-restart")
  229.             end
  230.         end
  231.         autoRestartTick()
  232.     end
  233. end
  234.  
  235.  
  236.  
  237.  
  238.